package com.weishenai.dao.impl;

import com.weishenai.Builder.BaseRule;
import com.weishenai.Entity.User;
import com.weishenai.Mapper.QueryMapper;
import com.weishenai.dao.UserDao;

import java.util.List;
import java.util.Map;

/**
 * @Auther: weishenai
 * @Date: 2021/10/04/20:17
 * @Description:
 */
public class UserDaoImpl implements UserDao {
    @Override
    public User getLoginUser(String username) {
        BaseRule baseRule = BaseRule.getInstance();
        baseRule.andEqual("name", username);
        List<Map<String, Object>> user = new QueryMapper().select(baseRule, "user");
        if (user == null || user.size() == 0) {
            return null;
        }
        return new User((String) user.get(0).get("id"), (String) user.get(0).get("name"), (int) user.get(0).get("age"), (String) user.get(0).get("sex"), (String) user.get(0).get("address"), (String) user.get(0).get("password"));
    }
}
